<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 为了解决回调地狱的问题，就诞生了新的技术方案：Promise
    // Promise是回调嵌套的语法糖
    function getData1 () {
      return new Promise((resolve, reject) => {
        const data = 'tom'
        setTimeout(() => {
          resolve(data)
        }, 1000)
      })
    }
    function getData2 () {
      return new Promise((resolve, reject) => {
        const data = 'jerry'
        setTimeout(() => {
          resolve(data)
        }, 2000)
      })
    }
    function getData3 () {
      return new Promise((resolve, reject) => {
        const data = 'spike'
        setTimeout(() => {
          resolve(data)
        }, 3000)
      })
    }
    // 顺序要求：spike -> tom -> jerry
    getData3()
      .then(ret => {
        console.log(ret)
        return getData1()
      })
      .then(ret => {
        console.log(ret)
        return getData2()
      })
      .then(ret => {
        console.log(ret)
      })
  </script>
</body>
</html>
